/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xos_http_protocol.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#ifndef __DATA_STRUCT_SESSION_H__
#define __DATA_STRUCT_SESSION_H__

#include "../tools/head.h"

namespace xos_http_protocol
{

    class session_impl : public xos_stl::mem_item< xos::release_impl< session_impl >, thread_lock >,
        public http::i_session
    {
    public:
        typedef xos::release_impl< session_impl > T;

    public:
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // 
        static int get_xos_item_data( ITEM_DATA*& item_ptr );

        static session_impl * get( const char * lpszId );
        static int remove( session_impl * pSession );
        static int heart( int interval_ms );

        static int static_user_init();
        static int static_user_term();

    public:
        session_impl();
        ~session_impl();

    protected:
        xos_box::i_lock_num * m_pLockNum;
        int m_nTimeToTimeout_ms;
        std::string m_id;

    protected:
        int init_data();

    public:
        int reset_timeout();
        int init();
        int term();

        // 
        // i_session method
        // 
    public:
        const char * id( const char * lpszId );
        int max_age( int nSecond );
        int release_ref();
        int add_ref();
        
    };

} // xos_http_protocol

#endif // __DATA_STRUCT_SESSION_H__
